package com.young.dubbo.protocol.http;



import com.young.dubbo.framework.Invocation;
import com.young.dubbo.framework.Protocol;
import com.young.dubbo.framework.URL;
import com.young.dubbo.register.RemoteMapRegister;

import java.util.List;

/**
 * 以http为通信心意的接口注册中心
 */
public class HttpProtocol implements Protocol {
    /**
     * 启动注册中心，并注册对应的服务
     * @param host
     * @param port
     * @param interfaceName
     */
    @Override
    public void start(String host, int port,String interfaceName) {
        new HttpServer().start(host,port,interfaceName);
    }


    /**
     * 发送请求
     * @param host
     * @param port
     * @param invocation
     * @return
     */
    @Override
    public String send(String host, int port, Invocation invocation) {
        return new HttpClient().send(host, port, invocation);
    }

    /**
     * 根据接口名称获取已经注册到注册中心的url地址
     * @param interfaceName
     * @return
     */
    @Override
    public List<URL> getUrls(String interfaceName) {
        return RemoteMapRegister.get(interfaceName);
    }
}
